/*
 * get
 * Gets an item or items from an object or array by property, index or index range
 */

objx.requires("objx.is", "objx.get");

objx.fn.get = function() {
	
	var 
		what = arguments[0],
		obj = this.obj()
	;
	
	var object_string_search = function() {
		var criteria = arguments[0].split('.');
		var o = arguments[1];
		var r = [];
		
		for(var i in o) 
		{
			var _ = o[i];
			for(var c in criteria) 
			{
				_ = _[criteria[c]];
			}
			
			r.push(_);
		}
		return objx(r);
	}

	switch (objx.type(what)) {
		case "string":
			if(what.indexOf('.') > 0) {
				return object_string_search(what,obj); 
			}
		case "number":
			if(arguments.length == 2 
				&& typeof(obj) == 'string' 
				&& typeof(arguments[1]) == 'number') 
			{
				return objx(obj.substring(arguments[0],arguments[1]));
			}
			
			// look for this property
			return objx(obj[what]);
			
			break;
	}
	
};

objx.provides("objx.get");